<!--
 * @Author: your name
 * @Date: 2022-04-12 10:29:19
 * @LastEditTime: 2022-04-12 10:33:46
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\遍历所有的属性和值220422.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>属性和值</title>
</head>
<body>
  <script>
    //name=geyao	age=18	sex=男	
    function allprops(obj){
      //用来保存所有的属性和值
      var props="";
      //开始遍历
      for(var p in obj){
        //方法
        if(typeof(obj[p])=="function"){
          obj[p]();
        }else{
          props+=p+"="+obj[p]+"\t"
        }
      }
      return props;
    }
    var geyao={
      name:"geyao",
      age:"18",
      sex:"男"
    }
    console.log(allprops(geyao))
  </script>
</body>
</html>